home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Visual Basic.60 / COMMON / TOOLS / VB / UNSUPPRT / VOICE / VCHATAPP / CHAT_FUN.BAS < prev    next >
Encoding:
BASIC Source File  |  1997-01-16  |  6.2 KB  |  117 lines

  1. Attribute VB_Name = "CHAT_Functions"
  2. Option Explicit
  3. Public Sub InitServerList(ServerList As ComboBox)
  4.     ' Populate Server List Box...
  5.     ServerList.AddItem "VBLABWK3"
  6.     ServerList.AddItem "VBLABWK9"
  7. End Sub
  8.  
  9. '--------------------------------------------------------------
  10. Public Sub DebugSocket(TCPSocket As Winsock)
  11. ' Prints Information In A TCP Socket, For Debugging TCP Events...
  12. '--------------------------------------------------------------
  13.     Debug.Print "TCPSocket.RemoteHost", TCPSocket.RemoteHost
  14.     Debug.Print "TCPSocket.RemoteHostIP", TCPSocket.RemoteHostIP
  15.     Debug.Print "TCPSocket.RemotePort", TCPSocket.RemotePort
  16.     Debug.Print "TCPSocket.LocalHostName", TCPSocket.LocalHostName
  17.     Debug.Print "TCPSocket.LocalIP", TCPSocket.LocalIP
  18.     Debug.Print "TCPSocket.LocalPort", TCPSocket.LocalPort
  19.     Debug.Print "TCPSocket.State", TCPSocket.State
  20.     Debug.Print "====================================================="
  21. '--------------------------------------------------------------
  22. End Sub
  23. '--------------------------------------------------------------
  24.  
  25. '------------------------------------------------------------------
  26. Public Sub ResPlaySound(ResourceId As Long)
  27. ' Uses Sound Play Sound To Play Back PreRecorded WaveFiles
  28. '------------------------------------------------------------------
  29.     Dim sndBuff As String
  30. '------------------------------------------------------------------
  31.     sndBuff = StrConv(LoadResData(ResourceId, "WAVE"), vbUnicode)
  32.     Call sndPlaySound(sndBuff, SND_SYNC Or SND_MEMORY)
  33. '------------------------------------------------------------------
  34. End Sub
  35. '------------------------------------------------------------------
  36.  
  37. '--------------------------------------------------------------
  38. Public Sub AddConnectionToList(Socket As Winsock, ConnList As ListBox)
  39. ' Adds A Connection Reference To A ListBox - [(Server)(LocalPort)(RemotePort)]
  40. '--------------------------------------------------------------
  41.     Dim MemberID As String                      ' Connection Reference Variable
  42. '--------------------------------------------------------------
  43.     ' Create MemberID From HostName and RemoteIP
  44.     MemberID = Socket.RemoteHostIP & "  [" & _
  45.                Format(Socket.RemotePort, "0") & "] - [" & _
  46.                Format(Socket.LocalPort, "0") & "]"
  47.  
  48.     ConnList.AddItem MemberID                   ' Add New Member To List
  49.     ConnList.ItemData(ConnList.NewIndex) = Socket.Index
  50. '--------------------------------------------------------------
  51. End Sub
  52. '--------------------------------------------------------------
  53.  
  54. '--------------------------------------------------------------
  55. Public Sub RemoveConnectionFromList(Socket As Winsock, ConnList As ListBox)
  56. ' Removes A Connection Reference From A ListBox
  57. '--------------------------------------------------------------
  58.     Dim Conn As Long                                ' Connection Array Element Variable
  59.     Dim MemberID As String                          ' Connection Reference Variable
  60. '--------------------------------------------------------------
  61.     ' Create MemberID From HostName and RemoteIP
  62.     MemberID = Socket.RemoteHostIP & "  [" & _
  63.                Format(Socket.RemotePort, "0") & "] - [" & _
  64.                Format(Socket.LocalPort, "0") & "]"
  65.     
  66.     For Conn = 0 To ConnList.ListCount - 1          ' Search Each Member In List
  67.         If (ConnList.List(Conn) = MemberID) Then    ' Look For MemberID In List
  68.             ConnList.RemoveItem Conn                ' Remove MemberID From List
  69.         End If
  70.     Next                                            ' Next Connection
  71. '--------------------------------------------------------------
  72. End Sub
  73. '--------------------------------------------------------------
  74.  
  75. '--------------------------------------------------------------
  76. Public Sub GetIdxFromMemberID(Sockets As Variant, MemberID As String, Index As Long)
  77. '--------------------------------------------------------------
  78.     Dim Idx As Long                                 ' Socket cntl index
  79.     Dim LocPortID As Long                           ' Local Port ID
  80.     Dim RemPortID As Long                           ' Remote Port ID
  81.     Dim RemoteIP As String                          ' Remote Host IP address
  82.     Dim sStart As Long                              ' Substring begin position
  83.     Dim sEnd As Long                                ' Substring end postition
  84.     Dim Socket As Winsock                               ' Winsock socket
  85. '--------------------------------------------------------------
  86.     sStart = 1
  87.     sEnd = InStr(1, MemberID, " ") - 1              ' Get end of remote ip address
  88.     If (sEnd > 1) Then
  89.         RemoteIP = Mid(MemberID, sStart, sEnd)      ' Get remote host ip address
  90.         sStart = InStr(sEnd, MemberID, "[") + 1     ' Get start of remote port
  91.         If (sStart > 1) Then                        ' If Start found
  92.             sEnd = InStr(sStart, MemberID, "]") - 1 ' Get end of remote port
  93.             If (sEnd > 2) Then                      ' If end found
  94.                 RemPortID = Val(Mid(MemberID, sStart, sEnd)) ' Get RemotePort
  95.                 sStart = InStr(sEnd, MemberID, "[") + 1      ' Get start of local port
  96.                 If (sStart > 1) Then
  97.                     sEnd = InStr(sStart, MemberID, "]") - 1  ' Get end of local port
  98.                     If (sEnd > 2) Then                       ' If End Found
  99.                         LocPortID = Val(Mid(MemberID, sStart, sEnd)) ' Extract local port
  100.                         For Each Socket In Sockets
  101.                             If ((Socket.RemoteHostIP = RemoteIP) And _
  102.                                 (Socket.RemotePort = RemPortID) And _
  103.                                 (Socket.LocalPort = LocPortID) And _
  104.                                 (Socket.Index > 0)) Then    ' Was a match found???
  105.                                 Index = Socket.Index        ' Save and return index
  106.                                 Exit Sub                    ' Done... exit
  107.                             End If
  108.                         Next
  109.                     End If
  110.                 End If
  111.             End If
  112.         End If
  113.     End If
  114. '--------------------------------------------------------------
  115. End Sub
  116. '--------------------------------------------------------------
  117.